import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:xim/common/get_style_view.dart';
import 'package:xim/screen/message_list_screen/page/chat_detail_page/chat_detail_controller.dart';
import 'package:xim/screen/message_list_screen/page/chat_detail_page/chat_detail_style.dart';
import 'package:xim/widget/dash_chat_2/dash_chat_2.dart';

final log = Logger();

/// 消息会话页面
class ChatDetailPage
    extends GetStyleControllerView<List<ChatMessage>, ChatDetailController, ChatDetailStyle> {

  /// 会话ID
  final int sessionId;

  ChatDetailPage({Key? key, required this.sessionId}) : super(key: key);

  @override
  Widget buildView(BuildContext context, data) {
    return Scaffold(
        backgroundColor: style.bgColor.color,
        appBar: style.appBar,
        body: Column(
          children: [
            Expanded(
                child: DashChat(
                  inputOptions: style.inputOptions(controller.sendFile, context),
                    scrollToBottomOptions: const ScrollToBottomOptions(disabled: true),
                    messageOptions: style.messageOptions(context),
                    messageListOptions: style.messageListOptions,
                    currentUser: controller.currChatUser,
                    onSend: (ChatMessage m) => controller.sendMessage(m),
                    messages: controller.chatMessages,
                    onDashClick: () {
                      log.i("click chat bash");
                      controller.closeBottomPanel();
                      FocusScope.of(context).requestFocus(FocusNode());
                    }
                )
            ),
            // 底部面板
            Obx(() {
              return AnimatedContainer(
                color: style.bgColor.color,
                duration: const Duration(milliseconds: 300,),
                height: controller.currBottomPanel.value?.height ?? 0,
                child: controller.currBottomPanel.value?.panel,
              );
            }),
          ],
        ));
  }

}
